#pragma once

#define DEFAULT_FILENAME    NULL  
#define DEFAULT_MAPNAME     L"_LT_SHARED_MEMORY_"  
#define DEFAULT_MAPSIZE     (0xFFFF + 1)


class CSharedMemory
{
public:
	CSharedMemory(void);
	~CSharedMemory(void);
	//////////////////////////////////////////////////////////////////////
	bool Create(const wchar_t *szMapName, DWORD dwSize);
	bool Read(void *pData, DWORD dwSize);
	bool Write(const void *pData, DWORD dwSize);

	LPVOID GetBuffer();
	DWORD GetSize();
	bool IsCreated();

	HANDLE  m_hMemoryEvent;

private:
	void Destroy();
	void Init();
protected:
	HANDLE  m_hBufEvent;
	HANDLE	m_hFileMap;
	LPVOID	m_lpFileMapBuffer;

	WCHAR	*m_pMapName;
	DWORD	m_dwSize;

	int		m_iCreateFlag;
private:
	DWORD m_ptrWrite;
	DWORD m_ptrRead;
public:
	void ResetReadPointer(void);
	void ResetWritePointer(void);
	BOOL SetReadPointer(int nPos);
	BOOL SetWritePointer(int nPos);
};
